package czopyk.model.cost;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.Validate;
import org.apache.log4j.Logger;

import com.espertech.esper.collection.Pair;

import czopyk.model.request.LoadClass;
import czopyk.model.request.Request;
import czopyk.model.structure.CenterClass;

public class InterferenceManager {

	private static final Logger lgr = Logger.getLogger(InterferenceManager.class);

	private final Map<Pair<CenterClass, LoadClass>, Double> mapping = new HashMap<Pair<CenterClass, LoadClass>, Double>();

	public Double getInterferenceFactor(CenterClass centerClass, Request request, int load) {
		Double factor = mapping.get(new Pair<CenterClass, LoadClass>(centerClass, request.getLc()));
		if (factor == null) {
			return 1.0;
		}
		return load == 0 ? 0 : ((load - 1) * factor) + 1;
	}

	public void registerInterferenceFactor(LoadClass lc, CenterClass cc, Double factor) {
		Validate.notNull(lc);
		Validate.notNull(cc);

		mapping.put(new Pair<CenterClass, LoadClass>(cc, lc), factor);
	}

}
